package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Userinfo userinfo = InputUtil.getInputObject(new Userinfo(),"删除记录","删除");
        System.out.println(userinfo);
        System.out.println(userinfo);


        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String userName = scanner.nextLine();

        try(Connection connection =  DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql = "DELETE FROM userinfo\n" +
                    "WHERE username = '"+userName+"'";
            int rows = statement.executeUpdate(sql);
            if(rows>0){
                System.out.println("删除成功");
            }else{
                System.out.println("删除失败");
            }


        }catch(SQLException e){
            e.printStackTrace();
        }


    }
}
